package demo1;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    public int uniquePathsWithObstacles(int[][] obstacleGrid) {

        int n = obstacleGrid.length;
        int m = obstacleGrid[0].length;
        if(obstacleGrid[0][0]==1) return 0;
        int[][] dp = new int[n+1][m+1];
        dp[1][1] = 1;
        for (int i = 1; i < n+1; i++) {
            for (int j = 1; j < m+1; j++) {
                if(i==1 && j==1) continue;
                if(obstacleGrid[i-1][j-1]!=1){
                    dp[i][j] = dp[i-1][j] + dp[i][j-1];
                }
            }
        }
        return dp[n][m];
    }

    public  static List<Integer> mostVisited(int n, int[] rounds) {
        List<Integer> res = new ArrayList<>();
        int[] freq = new int[n+1];

        int start = rounds[0];
        int max = 0;

        for (int i = 1; i < rounds.length; i++) {
            int end = rounds[i];
            while(start != end) {
                freq[start] ++;
                start = (start + 1) > n? 1 : (start +1);
            }
            freq[start] ++;
            start = (start + 1) > n? 1 : (start +1);
        }


        for (int i = 0; i < freq.length; i++) {
            max = Math.max(max, freq[i]);
        }

        for (int i = 0; i < freq.length; i++) {
            if(max == freq[i]) res.add(i);
        }
        return res;
    }
}
